export default function unMountNode(node) {
    const virtualDOM = node._virtualDOM
    if (virtualDOM.type === 'text') {
        node.remove()
        return
    }
    let component = virtualDOM.component
    // 组件
    if (component) {
        component.componentWillUnmount()
    }

    // 节点ref属性
    if (virtualDOM.props && virtualDOM.props.ref) {
        virtualDOM.props.ref(null)
    }
    // 删除事件
    Object.keys(virtualDOM.props).forEach(propName => {
        if (propName.slice(0, 2) === 'on') {
            const eventName = propName.slice(2).toLowerCase()
            const handler = virtualDOM.props[eventName]
            node.removeEventListener(eventName, handler)
        }
    })
    if (node.childNodes.length > 0) {
        node.childNodes.forEach(child => {
            unMountNode(child)
        })
    }
    node.remove()
}